//
//  ZyaStatusButton.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2025/1/3.
//  Copyright © 2025 zwb. All rights reserved.
//



class ZyaStatusButton: UIButton {
    //    0:未提交;1:审核中;2:未开始;3:进行中;4:已中标;5:已流标
    
    override func awakeFromNib() {
        configUI()
    }
    
    func configUI() {
        self.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        self.layer.cornerRadius = 11
         self.setTitleColor(.white, for: .normal)
    
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    
    func setBtnStyle(color:UIColor) {
             self.backgroundColor = color
     }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.titleLabel?.frame = CGRect(x: 13, y: 0, width: self.ks_width - 13, height: self.ks_height)
    }
    
    
    @discardableResult
    func setZBJPStatus(listType:TBandJPType,auditmark:Int,status:Int,tbType:ZTBInnerType) -> String {
        
        
        var btnName = ""
        if tbType == .tbMytbKHW {
//            if status == 1 {
//                btnName =  "已开标"
//                self.setBtnStyle(color: .red)
//            } else if status == 0 {
//                btnName =  "未中标"
//                self.setBtnStyle(color: .lightGray)
//            } else {
//                btnName =  "已放弃"
//            }
            
            
            switch status {
            case 0:
                btnName = "未开始"
                self.setBtnStyle(color: UIColor(kshex: tenderBlue))
            case 1:
                btnName = listType == .TB ? "已开标" : "已成交"
                self.setBtnStyle(color: UIColor(kshex: tenderGreen))
            case 2:
                btnName = "进行中"
                self.setBtnStyle(color: .red)

            case 3:
                btnName = "已结束"
                self.setBtnStyle(color: UIColor.lightGray)
            case 4:
                btnName = listType == .TB ? "已流标" : "已流拍"
                self.setBtnStyle(color: UIColor.lightGray)
            default:
                print("33")
            }
//            
        } else
        if tbType == .tbRecordKHW {
            if status == 1 {
                btnName =  "已中标"
                self.setBtnStyle(color: .red)
            } else if status == 0 {
                btnName =  "未中标"
                self.setBtnStyle(color: .lightGray)
            } else {
                btnName =  "已放弃"
                self.setBtnStyle(color: .lightGray)
            }
            
        } else if tbType == .chujiaRecordKHW {
                   if status == 1 {
                       btnName =  "已成交"
                       self.setBtnStyle(color: UIColor(kshex: tenderGreen))

                   } else if status == 0 {
                       btnName =  "未成交"
                       self.setBtnStyle(color: UIColor(kshex: tenderBlue))
                   } else {
                       btnName =  "已结束"
                       self.setBtnStyle(color: UIColor.lightGray)
                   }
        } else if tbType == .zbAnnouncementKHW {
            btnName = "已开标"
            self.setBtnStyle(color: .red)
        } else if tbType == .chujiaRecordJP {
            btnName = "已出价"
        } else if tbType == .cjAnnouncementKHW {
            btnName = "已开拍"
            self.setBtnStyle(color: UIColor(kshex: tenderGreen))
        } else {
            if auditmark == 1 {
                switch status {
                case 0:
                    btnName = "未开始"
                    self.setBtnStyle(color: UIColor(kshex: tenderBlue))
                case 1:
                    btnName = listType == .TB ? "已开标" : "已成交"
                    self.setBtnStyle(color: UIColor(kshex: tenderGreen))
                case 2:
                    btnName = "进行中"
                    self.setBtnStyle(color: .red)

                case 3:
                    btnName = "已结束"
                    self.setBtnStyle(color: UIColor.lightGray)
                case 4:
                    btnName = listType == .TB ? "已流标" : "已流拍"
                    self.setBtnStyle(color: UIColor.lightGray)
                default:
                    print("33")
                }
            } else if auditmark == 0 {
                btnName = "未提交"
                self.setBtnStyle(color: UIColor(kshex: tenderBlue))
            } else if auditmark == 2 {
                btnName = "已退回"
                self.setBtnStyle(color: UIColor.lightGray)
            } else if auditmark == 9 {
                btnName = "已提交"
                self.setBtnStyle(color: UIColor(kshex: tenderGreen))
            }
        }
        self.setTitle(btnName, for: .normal)
        return btnName
    }
    
    
}
